#pragma once
#include <kungfu/wingchun/msg.h>
#include <kungfu/yijinjing/common.h>
#include "kungfu/wingchun/book/book.h"

using namespace rxcpp;
using namespace kungfu::wingchun::msg::data;

namespace junyi
{
    namespace mint
    {
        namespace wrapper
        {
			class MBook: public kungfu::wingchun::book::Book
			{
			public:
				MBook(const kungfu::yijinjing::data::location_ptr& location);

				~MBook() {};

                virtual void on_quote(kungfu::yijinjing::event_ptr event, const kungfu::wingchun::msg::data::Quote& quote);

                virtual void on_trade(kungfu::yijinjing::event_ptr event, const kungfu::wingchun::msg::data::Trade& trade);

                virtual void on_order(kungfu::yijinjing::event_ptr event, const kungfu::wingchun::msg::data::Order& order);

                virtual void on_order_input(kungfu::yijinjing::event_ptr event, const kungfu::wingchun::msg::data::OrderInput& input);

                virtual void on_positions(const std::vector<kungfu::wingchun::msg::data::Position>& positions);

                virtual void on_position_details(const std::vector<kungfu::wingchun::msg::data::PositionDetail>& position_details);

                virtual void on_asset(kungfu::yijinjing::event_ptr event, const kungfu::wingchun::msg::data::Asset& asset);

                virtual void on_trading_day(kungfu::yijinjing::event_ptr event, int64_t daytime);


                void add_book_position(std::shared_ptr<Position> position_ptr);

                void add_book_subject(rxcpp::subjects::subject<kungfu::yijinjing::event_ptr>& subject);

                uint32_t get_position_uid(std::string instrument_id, std::string exchange_id, std::int32_t direction);

                std::string get_position_uname(std::string instrument_id, std::string exchange_id, std::int32_t direction);

			private:
                kungfu::yijinjing::data::location_ptr location_;

                rxcpp::subjects::subject<kungfu::yijinjing::event_ptr> subject_;

                std::unordered_map<uint32_t, std::shared_ptr<Position>> positions_;
			};
        }
    }
}